<?php
/**
 *	KLF Framework
 *
 *	Written by Kristian Oye <kristianoye@gmail.com> on Oct 23, 2011
 *	Copyright (C) 2010-2011
 */
namespace KLF\System\Web
{
	/**
	 * Provides various utility functions.
	 * @author kristian
	 */
	use KLF\System\Data\KPreferenceMap;

	class KHttpUtility
	{
		/**
		 * Looks for the first defined value in a list of possible values.
		 * @param param
		 * @returns mixed Value
		 */
		public static function ChainGet()
		{
			$args = func_get_args();
			$sz = count($args);
			
			for($i=0; $i<$sz-1; $i+=2)
			{
				$a = $args[$i];
				$b = ($i + 1 < $sz ? $args[$i + 1] : null);
				$c = (isset($b) && isset($a[$b]) ? $a[$b] : null);
				
				if (isset($c))
					return $c;
			}
			
			return ($i < $sz ? $args[$i] : null);
		}
		
		/**
		 * @param string Raw value containing a weighted preference list (language, etc).
		 * @return KPreferenceMap
		 */
		public static function CreatePreferenceMap($prefName, $strValue)
		{
			return new KPreferenceMap($prefName, $strValue);
		}
	}
}
